<?php
  global $base_url;
  $modPath = drupal_get_path('module', 'e_district');
?>

<style>
  .tableHeaderst{
    background-color: #ADDBF3;
  	border:1px solid #2676BD;
    font-weight: bold;
  }

  .tableHeaderst1 {
    border:1px solid #2676BD;

  }
  .form-submit {
     background-color: #5B74A8;
     border: 0px none;
     height: 22px;
     cursor: pointer;
     color: #FFF;
     font-weight: bold;
     font-family: Verdana,Arial,Helvetica,sans-serif;
  }

</style>

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<script>
	$(function() {
			$( "#datepicker" ).datepicker({
			maxDate: new Date(),
			dateFormat: 'dd-mm-yy',
			showOn: "button",
			buttonImage: "<?php echo $modPath?>/image/calendar.gif",
			buttonImageOnly: true

		});

	});

	function validateForm() {
	    var x = document.getElementById('datepicker').value;
	    if (x == null || x == "") {
	        alert("Please choose the Date");
	        return false;
	    }
	}

</script>


  <div class="clear-block">
  <p style="color:#000099;font-weight:bold;font-size:16px;text-align: center;">e-Districts statistics</p>
  <form name="stat" id="stat" method="post" onsubmit="return validateForm()">
      <table width="618" border="0" style="text-align: center;">
        <tr>
          <td width="334">Date:
            <input type="text" id="datepicker" size="30" name='datepicker' readonly="" /></td>
      	<td width="274"><p> <input type="submit" id="val" size="30" name='val' value="get data" class="form-submit"/></p></td>

        </tr>
      </table>
   </form>


<?php

  if( ! ini_get('date.timezone') )
  {
      date_default_timezone_set('GMT');
  }

  if(isset($_REQUEST['datepicker'])){

  $start = trim($_REQUEST['datepicker']);

  $cur_date  = trim(date('d/m/Y',strtotime("-1 days")));

  $cur_date  = trim(date('d/m/Y',strtotime("-1 days")));

  $date_val_st = date('d/m/Y',strtotime($start));

  ?> <span><strong>Statistics as on date: <?php echo $date_val_st; ?> </strong></span> <?php
  //$curl = curl_init('http://164.100.167.34:8080/edistrict_tn_deity/Date/'.$date_val.'/');

  /* 1.Statistics as on date: 19/11/2014 */

  $curl = curl_init('http://164.100.167.34:8080/edistrict_tn_deity/Date/' . $date_val_st .'/');
  //$curl = curl_init('http://164.100.167.34:8080/edistrict_tn_deity/Date/15/10/2014');



  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_USERPWD, 'eportal:wyua2612');
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);


  $response = curl_exec($curl);
  $resultStatus = curl_getinfo($curl);
  $fp = fopen('statistics.xml', 'w');
  chmod("statistics.xml",0777);
  $xml = simplexml_load_string($response);

 ?>
  <table width="100%" border="0" style="margin-left: 20px;">
    <tr class="tableHeaderst">
      <th>S.No</th>
      <th>Department</th>
      <th>Service</th>
      <th>Applications Recieved</th>
      <th>Applications Rejected</th>
      <th>Applications Processed</th>
      <th>Applications Pending</th>
    </tr>
  <?php
  if(count($xml)){


  foreach($xml as $data){  ?>

    <tr class="tableHeaderst1">
      <td><?php echo $data->slno;?></td>
      <td><?php echo $data->Department;?></td>
      <td><?php echo $data->Service;?></td>
      <td><?php echo $data->ApplicationsRecieved;?></td>
      <td><?php echo $data->ApplicationsRejected;?></td>
      <td><?php echo $data->ApplicationsProcessed;?></td>
      <td><?php echo $data->ApplicationsPending;?></td>
    </tr>
  <?php } ?>
  <?php } else{ ?>

   <tr class="tableHeaderst1">
      <td></td>
      <td></td>
      <td></td>
      <td>Record not found</td>
      <td></td>
      <td></td>
      <td></td>
    </tr>

  	<?php } ?>

  </table>

  <?php
  curl_close($curl);
  ?>
  <?php  }  ?>

  <div style="color:brown;font-weight:bold;font-size:16px; margin-top:35px; margin-left: 135px; margin-bottom: 10px;">e-Districts  Transaction Status</div>

  <?php
  $this_month = mktime(0, 0, 0, date('m'), 1, date('Y'));
  $current_month= date("m", strtotime("+0 month", $this_month));

  ?>
  <table width="100%" border="0" style="margin-left: 20px;">
    <tr class="tableHeaderst">
      <th>Cumulative </th>
      <th><?php echo date("F - Y", strtotime("-2 month", $this_month)); ?> </th>
      <th><?php echo date("F - Y", strtotime("-1 month", $this_month)); ?> </th>

    </tr>
    <tr class="tableHeaderst1">
      <td><a href="<?php echo $modPath; ?>/cumulative_report_total.php" target="_blank" >Cumulative</a></td>
      <td><a href="<?php echo $modPath; ?>/cumulative_report_last2month.php" target="_blank" ><?php echo date("FY", strtotime("-2 month", $this_month)); ?> </a></td>
      <td><a href="<?php echo $modPath; ?>/cumulative_report_lastmonth.php" target="_blank" ><?php echo date("FY", strtotime("-1 month", $this_month)); ?> </a></td>

    </tr>
    </table>
